/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.db.generator.field.models;

/**
 *
 * @author abosancic
 */
import java.sql.Types;

public class SQLTypeMap {

  /**
   * Translates a data type from an integer (java.sql.Types value) to a string
   * that represents the corresponding class.
   * 
   * @param type The java.sql.Types value to convert to a string representation.
   * @return The class name that corresponds to the given java.sql.Types value,
   *         or "java.lang.Object" if the type has no known mapping.
   */
  public static String convert( int type ) {
    String result = "java.lang.Object";
    
    switch( type ) {
      case Types.CHAR:
      case Types.VARCHAR:
      case Types.LONGVARCHAR:
        result = "java.lang.String";
        break;

      case Types.NUMERIC:
      case Types.DECIMAL:
        result = "java.math.BigDecimal";
        break;

//      case Types.BIT:
//        result = "java.lang.Boolean";
//        break;
      
      case Types.BIT:
        result = "boolean";
        break;    

      case Types.TINYINT:
        result = "java.lang.Byte";
        break;

      case Types.SMALLINT:
        result = "java.lang.Short";
        break;

      case Types.INTEGER:
        result = "java.lang.Integer";
        break;

      case Types.BIGINT:
        result = "java.lang.Long";
        break;

      case Types.REAL:
        result = "java.lang.Float";
        break;

      case Types.FLOAT:
      case Types.DOUBLE:
        result = "java.lang.Double";
        break;

      case Types.BINARY:
        result = "java.io.InputStream";
        break;
          
      case Types.VARBINARY:
      case Types.LONGVARBINARY:
        result = "java.lang.Byte[]";
        break;

      case Types.TIME:
          result = "java.sql.Time";
        break;
          
      case Types.TIMESTAMP: 
          result = "java.sql.Timestamp";
        break;
          
      case Types.DATE:
        result = "java.sql.Date";
        break;
    }

    return result;
  }
  
  /**
   * Translates a data type from an integer (java.sql.Types value) to a string
   * that represents the corresponding class.
   * 
   * @param type The java.sql.Types value to convert to a string representation.
   * @return The class name that corresponds to the given java.sql.Types value,
   *         or "java.lang.Object" if the type has no known mapping.
   */
  public static String convert( String type ) {
      int types = new Integer(type).intValue();
      return convert(types);
  }
  
}
